<template>
  <div class="container">
    <el-card style="position: relative">
      <div class="top-content">
        <div class="editTitle">
          {{ title() }}
        </div>
        <div class="button_ok">
          <el-button
            v-if="(route.query.id && form.projectStatus == 1 && form.archivingStatus == 0) && userStore.rolescode!=15"
            type="primary"
            @click="confirmPigeonhole"
            >项目完成，确认归档</el-button
          >
        </div>
        <div class="button-content">
          <el-button
            class="button_back"
            link
            type="primary"
            @click="$router.go(-1)"
          >
            <el-icon>
              <Close />
            </el-icon>
          </el-button>
        </div>
      </div>
      <el-form
        :model="form"
        :rules="rules"
        ref="ruleFormRef"
        label-width="140px"
        size="mini"
        label-position="right"
        validate-on-rule-change
      >
        <el-row :gutter="20" class="form-single-info">
          <el-col :span="20">
            <div class="title"><h5>基本信息</h5></div>
            <el-row>
              <el-col :span="12">
                <el-form-item label="项目名称" prop="projectName">
                  <el-input
                    class="input-item"
                    v-model="form.projectName"
                    placeholder="请输入"
                    :disabled="isDisabled()"
                  ></el-input>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="项目编号" prop="projectId">
                  <el-input
                    class="input-item"
                    v-model="form.projectId"
                    placeholder="请输入"
                    :disabled="isDisabled()"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="业务类型" prop="businessTypeList">
                  <el-cascader
                    v-model="form.businessTypeList"
                    ref="ref_business"
                    :options="businesstypeTree"
                    :props="businesstProps"
                    :show-all-levels="true"
                    clearable
                    @change="businessChange"
                    :disabled="isDisabled()"
                  ></el-cascader>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="业主单位" prop="enterpriseName">
                  <el-input
                    class="input-item"
                    v-model="form.enterpriseName"
                    placeholder="请输入"
                    :disabled="isDisabled()"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="项目联系人" prop="enterprisePerson">
                  <el-input
                    class="input-item"
                    v-model="form.enterprisePerson"
                    placeholder="请输入"
                    :disabled="isDisabled()"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="项目联系人电话" prop="enterprisePhone">
                  <el-input
                    class="input-item"
                    v-model="form.enterprisePhone"
                    placeholder="请输入"
                    :disabled="isDisabled()"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="预计合同金额" prop="expectedContractMoney">
                  <el-input
                    type="number"
                    class="input-item"
                    v-model="form.expectedContractMoney"
                    placeholder="请输入"
                    :disabled="isDisabled()"
                  >
                    <template #append>
                      <el-select
                        v-model="form.unites"
                        placeholder="请选择"
                        style="width: 115px"
                      >
                        <el-option
                          v-for="item in unitsList"
                          :key="item.value"
                          :label="item.label"
                          :value="item.label"
                        >
                        </el-option>
                      </el-select>
                    </template>
                  </el-input>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="项目总投资额">
                  <el-input
                    type="number"
                    class="input-item"
                    v-model="form.investment"
                    placeholder="请输入"
                    :disabled="isDisabled()"
                  >
                    <template #append> 万元 </template>
                  </el-input>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="所在地区" prop="addressList">
                  <el-cascader
                    v-model="form.addressList"
                    ref="ref_areaCodes"
                    :options="areaList"
                    :props="areaCodeprops"
                    :show-all-levels="true"
                    clearable
                    @change="areaCodesChange"
                    :disabled="isDisabled()"
                  ></el-cascader>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="行业" prop="industrys">
                  <el-select
                    v-model="form.industrys"
                    multiple
                    filterable
                    allow-create
                    default-first-option
                    :reserve-keyword="false"
                    placeholder="请输入"
                    :disabled="isDisabled()"
                  >
                    <el-option
                      v-for="item in industryDownOption"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    />
                  </el-select>
                </el-form-item>
              </el-col>

              <!-- <el-col :span="12">
                <el-form-item label="项目属性" prop="projectProperty">
                  <el-input
                    class="input-item"
                    v-model="form.projectProperty"
                    placeholder="请输入"
                    :disabled="isDisabled()"
                  ></el-input>
                </el-form-item>
              </el-col> -->
              <el-col :span="12">
                <el-form-item label="审批部门">
                  <el-select
                    v-model="form.approvaDepts"
                    multiple
                    filterable
                    allow-create
                    default-first-option
                    :reserve-keyword="false"
                    placeholder="请输入"
                    :disabled="isDisabled()"
                  >
                    <el-option
                      v-for="item in approvalDeptOptions"
                      :key="item.id"
                      :label="item.label"
                      :value="item.id"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="监督部门">
                  <el-select
                    class="input-item"
                    v-model="form.superviseDepts"
                    placeholder="请选择"
                    multiple
                    filterable
                    allow-create
                    default-first-option
                    :reserve-keyword="false"
                    :disabled="isDisabled()"
                  >
                    <el-option
                      v-for="item in superviseDeptOptions"
                      :key="item.id"
                      :label="item.label"
                      :value="item.id"
                    />
                  </el-select>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="合同工期" prop="datetime">
                  <el-date-picker
                    v-model="datetime"
                    type="daterange"
                    range-separator="To"
                    start-placeholder="请选择"
                    end-placeholder="请选择"
                    format="YYYY-MM-DD"
                    value-format="YYYY-MM-DD"
                    :disabled="isDisabled()"
                  />
                </el-form-item>
              </el-col>

              <el-col :span="24">
                <el-form-item label="投标项目" prop="tenderProject">
                  <el-radio-group
                    v-model="form.tenderProject"
                    :disabled="isDisabled()"
                  >
                    <el-radio :label="0">否</el-radio>
                    <el-radio :label="1">是</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="上传进度计划表" prop="contractFileList">
                  <!-- {{form.contractFileList}} -->
                  <fileupload v-if="ist == '3'"
                    @update:modelValue="handleContractFile"
                    :modelValue="form.contractFileList"
                    :flag="route.query.name === '3' || route.query.name === '6'"
                  ></fileupload>
                  <indexcategory v-if="ist == '1'"
                    @update:modelValue="handleContractFile"
                    :modelValue="form.contractFileList"
                    :flag="route.query.name === '3' || route.query.name === '6'">
                  </indexcategory>
                  <indexcategorysecond v-if="ist == '2'"
                    @update:modelValue="handleContractFile"
                    :modelValue="form.contractFileList"
                    :flag="route.query.name === '3' || route.query.name === '6'">
                  </indexcategorysecond>
                </el-form-item>
              </el-col>

              <!-- <el-col :span="24">
                <el-form-item label="保密协议" prop="secrecyAgreement">
                  <el-radio-group
                    v-model="form.secrecyAgreement"
                    :disabled="isDisabled()"
                  >
                    <el-radio :label="0">否</el-radio>
                    <el-radio :label="1">是</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="24" v-if="form.secrecyAgreement === 1">
                <el-form-item
                  label="上传保密协议"
                  prop="secrecyAgreementFileList"
                >
                  <fileupload
                    @update:modelValue="handleModelValueUpdate"
                    :modelValue="form.secrecyAgreementFileList"
                  ></fileupload>
                </el-form-item>
              </el-col> -->

              <!-- <el-col :span="24">
                <el-form-item label="优先级" prop="priority">
                  <el-select
                    v-model="form.priority"
                    clearable
                    placeholder="请选择"
                    style="width: 240px"
                    @change="changePriority"
                    :disabled="isDisabled()"
                  >
                    <el-option
                      v-for="item in priorityOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col> -->
              <el-col :span="24">
                <el-form-item label="项目简述" prop="projectBriefly">
                  <el-input
                    class="input-item"
                    type="textarea"
                    :autosize="{ minRows: 2 }"
                    show-word-limit
                    v-model="form.projectBriefly"
                    placeholder="请输入"
                    :disabled="isDisabled()"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="项目备注" prop="projectRemark">
                  <el-input
                    class="input-item"
                    type="textarea"
                    :autosize="{ minRows: 2 }"
                    show-word-limit
                    v-model="form.projectRemark"
                    placeholder="请输入"
                    :disabled="isDisabled()"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="上传附件/图片" prop="projectAnnexList">
                  <fileupload v-if="ist == '3'"
                    @update:modelValue="handleModelValueFile"
                    :modelValue="form.projectAnnexList"
                    :flag="route.query.name === '3' || route.query.name === '6'"
                  ></fileupload>
                  <indexcategory v-if="ist == '1'"
                    @update:modelValue="handleModelValueFile"
                    :modelValue="form.projectAnnexList"
                    :flag="route.query.name === '3' || route.query.name === '6'">
                  </indexcategory>
                  <indexcategorysecond v-if="ist == '2'"
                    @update:modelValue="handleModelValueFile"
                    :modelValue="form.projectAnnexList"
                    :flag="route.query.name === '3' || route.query.name === '6'">
                  </indexcategorysecond>
                </el-form-item>
              </el-col>
            </el-row>
            <div class="title">
              <h5>项目成员</h5>
              <selectPeople
                ref="childRef"
                :projectUserDtoList="form.projectUserDtoList"
                @selectTable="selectTable"
                @deleteTable="deleteTable"
                @handelChange="handelChange"
              ></selectPeople>
              <!-- <el-button
                type="primary"
                link
                @click="setPeople"
                :disabled="isDisabled()"
                >添加成员</el-button
              > -->
            </div>
            <div class="table-content">
              <el-table
                :data="form.projectUserDtoList"
                size="mini"
                style="width: 100%"
                header-cell-class-name="table-header-gray"
              >
                <el-table-column
                  type="index"
                  align="center"
                  width="50"
                  label="序号"
                ></el-table-column>
                <el-table-column
                  prop="nickName"
                  align="center"
                  label="姓名"
                ></el-table-column>
                <el-table-column
                  prop="phonenumber"
                  align="center"
                  label="手机号"
                ></el-table-column>
                <el-table-column
                  prop="projectRole"
                  align="center"
                  label="项目角色"
                >
                  <template #default="scope">
                    {{ parojectRoleTab(scope.row.projectRole) }}
                  </template>
                </el-table-column>
                <el-table-column
                  prop="dept.deptName"
                  align="center"
                  label="部门"
                  show-overflow-tooltip
                >
                </el-table-column>
                <el-table-column prop="postName" align="center" label="岗位">
                  <template #default="scope">
                    <div v-for="(item, index) in scope.row.posts" :key="index">
                      {{ item.postName }}
                    </div>
                  </template>
                </el-table-column>
                <el-table-column
                  align="center"
                  label="操作"
                  v-if="
                    route.query.name === '1' ||
                    route.query.name === '2' ||
                    (route.query.name === '3' &&
                      route.path === '/myProject/approval/edit')
                  "
                >
                  <template #default="scope">
                    <!-- <div @click="tableDelect(scope.row)">删除</div> -->
                    <div
                      v-if="
                        (route.query.name === '1' &&
                          userStore.userId !== scope.row.userId) ||
                        route.query.name === '2' ||
                        (route.query.name === '3' &&
                          route.path === '/myProject/approval/edit')
                      "
                    >
                      <el-tag
                        @click="tableDelect(scope.$index, scope.row)"
                        style="cursor: pointer"
                        >删除</el-tag
                      >
                    </div>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div class="title" v-if="route.query.name !== '1'">
              <h5>项目任务</h5>
            </div>
            <div class="table-content" v-if="route.query.name !== '1'">
              <el-table
                :data="form.projectTaskLists"
                size="mini"
                style="width: 100%"
                header-cell-class-name="table-header-gray"
              >
                <el-table-column
                  width="50"
                  type="index"
                  align="center"
                  label="序号"
                >
                </el-table-column>
                <el-table-column
                  prop="taskName"
                  align="center"
                  label="任务名称"
                >
                </el-table-column>
                <el-table-column
                  prop="taskStatus"
                  align="center"
                  label="任务状态"
                >
                  <template #default="scope">
                    {{
                      scope.row.taskStatus === "0" ||
                      scope.row.taskStatus === "2" ||
                      scope.row.taskStatus === "5"
                        ? "执行中"
                        : scope.row.taskStatus === "1"
                        ? "通过"
                        : scope.row.taskStatus === "4"
                        ? "已完成"
                        : ""
                    }}
                  </template>
                </el-table-column>
                <el-table-column
                  prop="auditStatus"
                  align="center"
                  label="审批状态"
                  show-overflow-tooltip
                >
                  <template #default="scope">
                    {{ auditStatusTab(scope.row.auditStatus) }}
                  </template>
                </el-table-column>
                <el-table-column align="center" label="操作">
                  <template #default="scope">
                    <el-button
                      link
                      type="primary"
                      size="small"
                      @click="handleClick(scope.row)"
                    >
                      详情
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div class="title" v-if="route.query.name !== '1'">
              <h5>意见栏</h5>
            </div>
            <div class="yijian" v-if="route.query.name !== '1'">
              <el-input
                class="input-yijian"
                type="textarea"
                :autosize="{ minRows: 2 }"
                show-word-limit
                v-model="form.opinion"
                placeholder="请输入内容"
                :disabled="isDisabled()"
              ></el-input>
            </div>
            <div class="fabu" v-if="route.query.name !== '1' && userStore.rolescode!=15">
              <el-button
                type="primary"
                size="mini"
                @click="publish"
                :disabled="isDisabled()"
                >发布</el-button
              >
            </div>
            <div
              class="text-content"
              v-if="route.query.name !== '1' && opinionList.length > 0"
            >
              <div
                class="custom-concent"
                v-for="item in opinionList"
                :key="item"
              >
                <!-- 图片头像 -->
                <div class="custom-wrapper">
                  <img :src="url + item.profilePicture" class="custom-avatar" />
                </div>
                <div class="custom-text">
                  <div class="text-top">
                    <div
                      style="
                        font-size: 16px;
                        font-weight: bold;
                        color: #ff8200;
                        white-space: nowrap;
                      "
                    >
                      {{ item.userName }}({{ item.departmentName }})：
                    </div>
                    <div class="text-time">{{ item.releaseTime }}</div>
                  </div>
                  <div class="text-bottom">
                    <div class="custom-reply">{{ item.viewContent }}</div>
                  </div>
                </div>
              </div>
            </div>


            <div v-if="route.query.name !== '1'">
              <div class="title" v-if="route.query.status !== '4'" ><h5>项目审批进度</h5></div>
              <el-timeline style="max-width: 600px" v-if="route.query.status !== '4'">
                <el-timeline-item
                  v-for="(activity, index) in activities"
                  :key="index"
                  :color="activity.color"
                  :timestamp="activity.updateTime"
                >
                  <div style="display: flex; align-items: center">
                    <img :src="url + activity.avatar" class="user-avatar" />
                    <span
                      style="
                        font-size: 14px;
                        font-weight: 500;
                        margin-left: 5px;
                      "
                    >
                      {{ activity.username }} ({{
                        activity.checkHisResult === "2" ? "未审核" : "已审核"
                      }})
                      {{
                        activity.zuofei === "0"
                          ? " _作废"
                          : activity.zuofei === "null"
                          ? ""
                          : ""
                      }}
                      :
                    </span>
                    <span
                      style="
                        font-size: 14px;
                        font-weight: 400;
                        margin-left: 5px;
                      "
                    >
                      {{ activity.opinion }}</span
                    >
                  </div>
                </el-timeline-item>
              </el-timeline>
            </div>

            <!-- 详情的时候 不展示 -->
            <div
              v-if="
                route.query.name === '1' ||
                route.query.name === '2' ||
                route.query.name === '6'
              "
              class="title"
            >
              <h5 v-if="keepCheck === '1'">项目审批流程</h5>
            </div>
            <el-row
              v-if="
                route.query.name === '1' ||
                route.query.name === '2' ||
                route.query.name === '6'
              "
            >
              <el-col :span="24">
                <el-form-item label="审批方式">
                  <el-radio-group
                    v-model="check.processCheckBo.checkType"
                    :disabled="isDisabled()"
                  >
                    <el-radio :label="0">自由审批</el-radio>
                    <el-radio :label="1">逐级审批</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item
                  label="审批流程"
                  style="padding: 20px 0"
                  v-if="
                    (route.query.name === '6' &&
                      check.processCheckBo.checkType === 0 &&
                      keepCheck === '1') ||
                    (route.query.name !== '6' && keepCheck === '1')
                  "
                >
                  <approver
                    :approverList="check.processCheckBo?.checkPeopleIds"
                    :typeId="3"
                    :isEdit="!!$route.query.projectId"
                    @handleChooseapprover="handleChooseapprover"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item
                  label="抄送"
                  style="padding: 20px 0"
                  v-if="
                    (route.query.name === '6' &&
                      check.processCheckBo.checkType === 0 &&
                      keepCheck === '1') ||
                    (route.query.name !== '6' && keepCheck === '1')
                  "
                >
                  <approver
                    :typeId="3"
                    :approverList="check.processCheckBo?.copyFor"
                    :isCc="true"
                    @handleChooseapprover="handleChooseapproverCc"
                  ></approver>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row v-if="route.query.name === '6' || route.query.name === '5'">
              <el-col :span="24">
                <el-form-item label="审批意见" prop="projectImplementation">
                  <el-input
                    class="input-item"
                    type="textarea"
                    :autosize="{ minRows: 2 }"
                    maxlength="150"
                    show-word-limit
                    v-model="form.approvalOpinions"
                    placeholder="请输入"
                    :disabled="route.query.name === '5' ? true : false"
                  ></el-input>
                </el-form-item>
                <el-form-item
                  label="添加附件/图片"
                  prop="projectImplementation"
                >
                  <fileupload :modelValue="approvalFile"
                    @update:modelValue="handleModelFileLists">
                  </fileupload>
                  <!-- <indexcategory v-else-if="userStore.deptId == 144" :modelValue="approvalFile"
                    @update:modelValue="handleModelFileLists">
                  </indexcategory> -->
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item
                  label="审批决定"
                  prop="projectImplementation"
                  v-if="check.processCheckBo.checkType !== 1"
                >
                  <el-radio-group
                    v-model="keepCheck"
                    class="ml-4"
                    :disabled="route.query.name === '5' ? true : false"
                  >
                    <el-radio label="0" size="large">完成审批</el-radio>
                    <el-radio label="1" size="large">继续审批</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
            <div
              v-if="hasButtonSave"
              style="display: flex; justify-content: center"
            >
              <el-button v-if="userStore.rolescode!=15" @click="resetForm(ruleFormRef)">{{
                route.query.name === "6" ? "驳回" : "取消"
              }}</el-button>
              <el-button v-if="userStore.rolescode!=15" type="primary" @click="submitForm(ruleFormRef)">{{
                route.query.name === "6" ? "通过" : "提交"
              }}</el-button>
            </div>

            <el-form-item
              v-if="route.query.name === '1' || route.query.name === '2'"
            >
              <div
                style="
                  width: 100vw;
                  margin-right: 140px;
                  display: flex;
                  justify-content: center;
                "
              >
                <el-button v-if="userStore.rolescode!=15" type="primary" @click="storage(ruleFormRef)">{{
                  route.query.id ? "保存" : "确认立项"
                }}</el-button>
              </div>
            </el-form-item>

            <el-form-item v-if="route.query.name === '3'">
              <div style=" width: 100vw;
                  margin-right: 140px;
                  display: flex;
                  justify-content: center;" >
                <el-button 
                v-if="route.query.createPerson == userStore.nickName && userStore.rolescode!=15 " 
                type="primary" @click="storage(ruleFormRef)">项目成员变动</el-button>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
  </div>
</template>
<script setup>
import { onMounted, reactive } from "vue";
import fileupload from "@/components/FileUpload/index";
import indexcategory from "@/components/FileUpload/indexcategory";
import indexcategorysecond from "@/components/FileUpload/indexcategorysecond";
import { useRouter, useRoute } from "vue-router";
import useUserStore from "@/store/modules/user";
import {
  businessTypeList,
  location,
  conversionDetailsList,
  getbusinessTypeDic
} from "@/api/project/conversion";
import {
  approvalProcessApi,
  approvalTransfer,
  lxapprovalApi,
} from "@/api/approvalManagement/approvaType.js";
import {
  approvalEdit,
  approvalQuery,
  approvalQueryApi,
  opinionRelease,
  opinionInquiry,
  approvalAdd,
  industryDownApi,
  approval,
  approvalDetailAdd,
} from "@/api/project/approval";
import selectPeople from "@/components/selector/selectPeople.vue";
import { collapseContextKey, ElMessage } from "element-plus";
import approver from "@/components/Approve/approver.vue";
import { useEmpty } from "@/utils/index";
let url = import.meta.env.VITE_APP_BASE_API;
const route = useRoute();
const router = useRouter();
const disabled = ref(false);
const detailsvisible = ref(false);
const keepCheck = ref("1");
const userStore = useUserStore();

// 头部标题
const title = () => {
  if (route.query.name === "1") {
    return "新建项目立项";
  } else if (route.query.name === "2") {
    return "编辑项目立项";
  } else if (route.query.name === "3") {
    return "详情项目立项";
  } else if (route.query.show) {
    return "转立项";
  } else {
    return "项目立项";
  }
};
// 优先级option
const priorityOptions = [
  {
    value: "1",
    label: "最高",
  },
  {
    value: "2",
    label: "较高",
  },
  {
    value: "3",
    label: "较低",
  },
  {
    value: "4",
    label: "最低",
  },
];
// 审批部门option
const approvalDeptOptions = ref([
  {
    id: "1",
    label: "生态环境局",
  },
  {
    id: "2",
    label: "行政审批局",
  },
  {
    id: "3",
    label: "经济发展局",
  },
  {
    id: "4",
    label: "发展改革局",
  },
  {
    id: "5",
    label: "其他",
  },
]);
const activities = ref([]);
// 监督部门option
const superviseDeptOptions = ref([
  {
    id: "1",
    label: "住建",
  },
  {
    id: "2",
    label: "采购办",
  },
  {
    id: "3",
    label: "水利",
  },
  {
    id: "4",
    label: "交通",
  },
  {
    id: "5",
    label: "发改",
  },
  {
    id: "6",
    label: "环保",
  },
  {
    id: "7",
    label: "其他",
  },
]);

const unitsList = [
  { value: "0", label: "元" },
  { value: "1", label: "万元" },
  { value: "2", label: "亿元" },
];

const childRef = ref(null);

let check = reactive({
  processCheckBo: {
    checkPeopleIds: [], //审核人id列表
    copyFor: [], //抄送人列表
    checkType: 1, //逐级审批
  },
});
// 表单数据
let form = reactive({
  projectName: "", //项目名称
  enterpriseName: "", //企业名称
  enterprisePhone: "", //项目联系人电话
  enterprisePerson: "", //项目联系人
  industrys: [], // 行业
  addressList: [], //所在地区
  projectProperty: "", //项目属性
  approvaDepts: [], // 审批部门
  superviseDepts: [], // 监督部门
  businessTypeList: [], // 业务类型
  secrecyAgreement: 0, //保密协议
  tenderProject: 0, // 投标项目
  projectBriefly: "", //项目简述
  projectRemark: "", //项目备注
  secrecyAgreementFile: "",
  secrecyAgreementFileList: [], //上传保密协议
  opinion: "", // 意见栏
  projectUserDtoList: [], // 项目成员表格
  projectTaskLists: [], //项目任务表格
  projectAnnex: "",
  projectAnnexList: [], //上传附件
  startDate: "", // 计划开始时间
  endDate: "", //计划结束时间
  priority: "", //  优先级
  proId: "", // 项目id
  // projectId: "",
  projectId: "", // 项目编号
  contractDuration: "", //
  approvalOpinions: "", // 审批意见
  unites: "",
  expectedContractMoney: "", //预计合同金额
  investment: "", //项目总投资额
  contractFile: "",
  contractFileList: [], //项目计划进度表
  processCheckHistoryId: "",
  archivingStatus:0,
  projectStatus:0,
  createPerson:""
});

const approvalFile = ref([]);

const datetime = ref();
// 开始时间
const contractDuration = ref();
// 结束时间
const contractTermination = ref();

// 审批人
const handleChooseapprover = (id) => {
  if (id) {
    check.processCheckBo.checkPeopleIds = id;
  }
};

// 抄送人
const handleChooseapproverCc = (id) => {
  if (id) {
    check.processCheckBo.copyFor = id;
  }
};

const handelChange = (row) => {
  if (form.projectUserDtoList && form.projectUserDtoList[0]) {
    form.projectUserDtoList[0].projectRole = row.projectRole;
  }
};
// 审批附件
const handleModelFileLists = (val, result, operationType) => {
  if (operationType === "success") {
    if (result) {
      approvalFile = [];
      result.forEach((item)=>{
        approvalFile.push(item);
      });
    }
  } else if (operationType === "delete") {
    approvalFile.value.splice(result, 1);
  }
};

// 删除
const tableDelect = (index, val) => {
  form.projectUserDtoList.splice(index, 1);
};
let checkPhone = (rule, value, callback) => {
  if (!value) {
    return callback(new Error("请输入项目联系人电话"));
  } else if (!/^(\d{1,4})-(\d{6,8})$/.test(value) && !/^1\d{10}$/.test(value)) {
    callback(new Error("项目联系人电话格式不正确"));
  } else {
    callback();
  }
};
const rules = reactive({
  projectName: [{ required: true, message: "请输入项目名称", trigger: "blur" }],
  projectId: [{ required: true, message: "请输入项目编号", trigger: "blur" }],
  enterpriseName: [
    { required: true, message: "请输入业主单位", trigger: "blur" },
  ],
  enterprisePhone: [
    { required: true, message: "请输入项目联系人电话", trigger: "blur" },
    { validator: checkPhone, trigger: "blur" },
  ],
  enterprisePerson: [
    { required: true, message: "请输入项目联系人", trigger: "blur" },
  ],
  addressList: [{ required: true, message: "请选择地区", trigger: "change" }],
  businessTypeList: [
    { required: true, message: "请选择业务类型", trigger: "change" },
  ],
  secrecyAgreementFileList: [
    { required: true, message: "请选择是否上传保密协议", trigger: "change" },
  ],
});

const hasButtonSave = ref(false);

// 1.按钮保存隐藏
const hasButton = () => {
  if (route.query.name !== "6") {
    hasButtonSave.value = false;
  } else {
    hasButtonSave.value = true;
  }
};
// 2.控制所有表单项是否只读
const isDisabled = () => {
  if (
    route.query.name === "3" ||
    route.query.name === "6" ||
    route.query.name === "5"
  ) {
    return (disabled.value = true);
  } else {
    return (disabled.value = false);
  }
};

const industryDownOption = ref([]);
// 获取行业下拉列表
const getindustryDown = async () => {
  const res = await industryDownApi();
  if (res.code === 200) {
    industryDownOption.value = res.data;
  }
};
let name = ref([]);
let id = ref([]);
// 立项页面点击编辑回显  根据ID查询单条数据
const approvalQueryInfo = async () => {
  let params = {
    id: Number(route.query.id),
  };
  const res = await approvalQuery(params);
  // 归档需要的参数
  if (res.code === 200) {
    name.value = res.data.projectName;
    id.value = res.data.proId;
  }
  if (res.code === 200 && typeof (res.data === "object")) {
    for (const key in form) {
      form[key] = res.data[key];
    }
    form.addressList = JSON.parse(res.data.address); // 所在地区
    form.businessTypeList = res.data.test; // 业务类型
    //通过判断业务类型的，来显示上传文件框
    ist.value = showFileUpload(res.data.test);

    form.projectAnnexList = res.data.projectFileList; // 添加附件
    form.secrecyAgreementFileList = res.data.secrecyFileList; // 保密协议文件
    datetime.value = [res.data.contractDuration, res.data.contractTermination];
    // 添加进度计划表
    form.projectTaskLists = res.data.projectTaskList;
    form.approvaDepts = JSON.parse(res.data.approvalDept);
    form.superviseDepts = JSON.parse(res.data.superviseDept);
    form.industrys = JSON.parse(res.data.industry);
    form.processCheckHistoryId = res.data.dataCheckInfo.processCheckHistoryId;
    check.processCheckBo.checkType = res.data.dataCheckInfo?.checkType;
    // form.expectedContractMoney=

    // 审批进度列表
    activities.value = res.data.dataCheckInfo.opinons;
    form.approvalOpinions =
      res.data &&
      res.data.dataCheckInfo &&
      res.data.dataCheckInfo.myCheckOpinionBo &&
      res.data.dataCheckInfo.myCheckOpinionBo.opinion;

    if (route.query.name === "5") {
      // 审批意见
      form.approvalOpinions =
        res.data &&
        res.data.dataCheckInfo &&
        res.data.dataCheckInfo.myCheckOpinionBo &&
        res.data.dataCheckInfo.myCheckOpinionBo.opinion;
      // 审批附件
      approvalFile.value =
        res.data &&
        res.data.dataCheckInfo &&
        res.data.dataCheckInfo.myCheckOpinionBo &&
        res.data.dataCheckInfo.myCheckOpinionBo.fileList;

      // 审批决定
      keepCheck.value =
        res.data &&
        res.data.dataCheckInfo &&
        res.data.dataCheckInfo.myCheckOpinionBo &&
        res.data.dataCheckInfo.myCheckOpinionBo.keepCheck;
    }

    // approvalFile.value =
    //   res.data &&
    //   res.data.dataCheckInfo &&
    //   res.data.dataCheckInfo.myCheckOpinionBo &&
    //   res.data.dataCheckInfo.myCheckOpinionBo.fileList;
  }
};

// 转立项回显 转立项ID查询单条数据
const handelApprovalQuery = async () => {
  let params = {
    id: Number(route.query.id),
  };
  const res = await approvalQueryApi(params);
  // 归档需要的参数
  if (res.code === 200) {
    name.value = res.data.projectName;
    id.value = res.data.proId;
  }
  if (res.code === 200 && typeof (res.data === "object")) {
    for (const key in form) {
      form[key] = res.data[key];
    }
    form.addressList = JSON.parse(res.data.address); // 所在地区
    form.businessTypeList = res.data.test; // 业务类型
    //通过判断业务类型的，来显示上传文件框
    ist.value = showFileUpload(res.data.test);

    form.projectAnnexList = res.data.projectFileList; // 添加附件
    form.secrecyAgreementFileList = res.data.secrecyFileList; // 保密协议文件
    datetime.value = [res.data.contractDuration, res.data.contractTermination];
    // 添加进度计划表
    form.projectTaskLists = res.data.projectTaskList;
    form.approvaDepts = JSON.parse(res.data.approvalDept);
    form.superviseDepts = JSON.parse(res.data.superviseDept);
    form.industrys = JSON.parse(res.data.industry);
    form.processCheckHistoryId = res.data.dataCheckInfo.processCheckHistoryId;
    // form.expectedContractMoney=

    // 审批进度列表
    activities.value = res.data.dataCheckInfo.opinons;
    form.approvalOpinions =
      res.data &&
      res.data.dataCheckInfo &&
      res.data.dataCheckInfo.myCheckOpinionBo &&
      res.data.dataCheckInfo.myCheckOpinionBo.opinion;

    if (route.query.name === "5") {
      // 审批意见
      form.approvalOpinions =
        res.data &&
        res.data.dataCheckInfo &&
        res.data.dataCheckInfo.myCheckOpinionBo &&
        res.data.dataCheckInfo.myCheckOpinionBo.opinion;
      // 审批附件
      approvalFile.value =
        res.data &&
        res.data.dataCheckInfo &&
        res.data.dataCheckInfo.myCheckOpinionBo &&
        res.data.dataCheckInfo.myCheckOpinionBo.fileList;

      // 审批决定
      keepCheck.value =
        res.data &&
        res.data.dataCheckInfo &&
        res.data.dataCheckInfo.myCheckOpinionBo &&
        res.data.dataCheckInfo.myCheckOpinionBo.keepCheck;
    }

    // approvalFile.value =
    //   res.data &&
    //   res.data.dataCheckInfo &&
    //   res.data.dataCheckInfo.myCheckOpinionBo &&
    //   res.data.dataCheckInfo.myCheckOpinionBo.fileList;
  }
};

// 转化页面点击转立项回显
const projectApproval = async () => {
  let id = route.query.planId;
  const res = await conversionDetailsList(id);
  if (res.code === 200 && res.data) {
    form.projectName = res.data.planName; // 项目名称
    form.enterpriseName = res.data.enterpriseName; // 企业名称
    form.enterprisePhone = res.data.contactPhone; // 项目联系人电话
    form.enterprisePerson = res.data.enterpriseContact; // 项目联系人
    form.industrys = JSON.parse(res.data.industry); // 行业
    form.addressList = JSON.parse(res.data.address); // 所在地区
    form.businessTypeList = res.data.test; // 业务类型
    //通过判断业务类型的，来显示上传文件框
    ist.value = showFileUpload(res.data.test);

    form.projectBriefly = res.data.projectBriefly; // 项目简述
    form.projectRemark = res.data.projectRemark; // 项目备注
    form.tenderProject = Number(res.data.tenderProject); // 投标项目
    form.secrecyAgreement = Number(res.data.secrecyAgreement); // 是否上传保密协议
    form.projectUserDtoList = res.data.projectUserDtoList; // 项目成员
    form.projectAnnexList = res.data.projectFileList; // 添加附件
    form.secrecyAgreementFileList = res.data.secrecyFileList; // 保密协议文件
    form.proId = res.data.planId;
    form.projectId = res.data.planEncode;
    form.planEncode = res.data.planEncode;
    form.investment = res.data.investment;
    form.expectedContractMoney = res.data.expectedContractMoney;
    form.approvaDepts = JSON.parse(res.data.approvalDept);
    form.superviseDepts = JSON.parse(res.data.superviseDept);
    datetime.value = [res.data.createContract, res.data.endContract];
    form.contractFileList = res.data.planscFileList;
    // console.log(res.data.planscFileList, "-- res.data.planscFileList---");
  }
};
// 项目完成，确认归档
const confirmPigeonhole = () => {
  if (useEmpty(form.projectTaskLists)) {
    ElMessage.warning("该项目没有任务无法归档");
    return false;
  } else {
    router.push({
      path: "/myProject/archive-info/add",
      query: {
        name: 1,
        id: Number(route.query.id ? route.query.id : route.query.planId),
        projectName: name.value,
        proId: id.value,
      },
    });
  }
};

// 业务类型树形列表
const businesstypeTree = ref([]);
// 获取业务类型树形列表
const businessTypeOptions = async () => {
  const response = await businessTypeList();
  if (response.code === 200 && response.data.length > 0) {
    businesstypeTree.value = response.data;
    // console.log(businesstypeTree.value);
  }
};
// 业务类型props配置
const businesstProps = {
  value: "id",
  label: "businessName",
  children: "children",
  checkStrictly: true,
  multiple: true,
};

const showFileUpload=(e)=>{
  //类型1为'a-j',类型2为'册'
  //返回值示例：
  // [
  //   {
  //       "type": "6,89",
  //       "value": 1
  //   },
  //   {
  //       "type": "[6,88],[6,90]",
  //       "value": 2
  //   }
  // ]

  //先判断类型1，再判断类型2，其它为3
  let typedic1 = businessTypeDicData.filter(o=>{ if(o.value == 1) return o } );
  let typedic2 = businessTypeDicData.filter(o=>{ if(o.value == 2) return o } );
  let result = '3';
  //进行业务类型的判断
  if(e.length == 0){
    return result;
  }
  e.forEach(function(item){
    typedic1.filter(function(o){
      let typearr = JSON.parse("["+ o.type +"]");
      typearr.forEach(function(p){
        if(p.length == 2 
        && p.length == item.length 
        && p[0] == item[0]
        && p[1] == item[1]){
          result = typedic1[0].value;
        }
        else if(p.length == 1 
        && p.length == item.length 
        && p[0] == item[0]){
          result = typedic1[0].value;
        }
      });
    });
  });

  if(result == '1'){
    return result;
  }
  e.forEach(function(item){
    typedic2.filter(function(o){
      let typearr = JSON.parse("["+ o.type +"]");
      typearr.forEach(function(p){
        if(p.length == 2 
        && p.length == item.length 
        && p[0] == item[0]
        && p[1] == item[1]){
          result = typedic2[0].value;
        }
        else if(p.length == 1 
        && p.length == item.length 
        && p[0] == item[0]){
          result = typedic2[0].value;
        }
      });
    });
  });

  return result;
}

// 切换业务类型
const ist = ref('3');
const businessChange = (e) => {
  // console.log(val, "--------dsdf");
  // console.log(form.businessType, "adaf");
  ist.value = showFileUpload(e);
};
// 全部地区列表
const areaList = ref([]);
const getareaList = async () => {
  const response = await location();
  if (response.code === 200 && response.data.length > 0) {
    areaList.value = response.data;
    // console.log(areaList.value);
  }
};
// 全部地区配置
const areaCodeprops = {
  label: "name",
  children: "rcDistrictList",
  value: "id",
  multiple: true
  // checkStrictly: true,
};
// 切换地区
const areaCodesChange = (val) => {
  console.log(val);
};
// 切换优先级
const changePriority = (val) => {
  console.log(val);
};

// 成功调取上传文件接口 上传保密协议
const handleModelValueUpdate = (val, result, operationType) => {
  if (operationType === "success") {
    if (result) {
      if (form.secrecyAgreementFileList === null) {
        form.secrecyAgreementFileList = [];
        form.secrecyAgreementFileList.push(result);
      } else {
        form.secrecyAgreementFileList.push(result);
      }
    }
  } else if (operationType === "delete") {
    form.secrecyAgreementFileList.splice(result, 1);
  }
};
// 上传附件
const handleModelValueFile = (val, result, operationType) => {
  if (operationType === "success") {
    if (result) {
      form.projectAnnexList = [];
        result.forEach((item)=>{
          form.projectAnnexList.push(item);
        });
    }
  } else if (operationType === "delete") {
    form.projectAnnexList.splice(result, 1);
  }
};

// 上传计划进度表
const handleContractFile = (val, result, operationType) => {
  if (operationType === "success") {
    if (result) {
      form.contractFileList = [];
        result.forEach((item)=>{
          form.contractFileList.push(item);
        });
    }
  } else if (operationType === "delete") {
    form.contractFileList.splice(result, 1);
  }
};

// 项目任务列表的审核状态处理
const auditStatusTab = (auditStatus) => {
  if (auditStatus === "2") {
    return "任务交付未审核";
  } else if (auditStatus === "0") {
    return "任务交付审核驳回";
  } else if (auditStatus === "1") {
    return "任务交付审核通过";
  } else if (auditStatus === "4") {
    return "成果交付审核通过";
  } else if (auditStatus === "5") {
    return "成果交付待审核";
  } else if (auditStatus === "6") {
    return "成果交付驳回";
  } else if (auditStatus === "7") {
    return "任务撤回";
  } else if (auditStatus === "8") {
    return "成果撤回";
  } else {
    return "";
  }
};
// 添加成员
const setPeople = () => {
  detailsvisible.value = true;
};
const roleList = [
  {
    id: "1",
    label: "主管领导",
  },
  {
    id: "2",
    label: "项目经理",
  },
  {
    id: "3",
    label: "项目助理",
  },
];
// 成员中项目角色的处理
const parojectRoleTab = (projectRole) => {
  let roleTranstion = roleList.find((item) => item.id === projectRole);
  return roleTranstion ? roleTranstion.label : "";
};
// 点击选择之后
const selectTable = (listVal) => {
  if (form.projectUserDtoList === null) {
    form.projectUserDtoList = [];
  }
  if (listVal) {
    form.projectUserDtoList.push(listVal);
  }
};
let optionsRole;
// 点击取消之后
const deleteTable = (val, index1) => {
  if (val) {
    form.projectUserDtoList.forEach((item, indexs) => {
      if (item.userId === val.userId) {
        form.projectUserDtoList.splice(indexs, 1);
      }
    });
  }
};
// 选择人员关闭
const handleClose = () => {
  detailsvisible.value = false;
  if (childRef.value) {
    childRef.value.formInline.nickName = "";
    childRef.value.formInline.deptId = "";
  }
};
// 任务详情
const handleClick = (row) => {
  router.push({
    path: "/taskManage/manage-add/add",
    query: {
      taskId: row.taskId,
      id: row.proId,
      name: 3,
      task:
        row.auditStatus === "0" ||
        row.auditStatus === "1" ||
        row.auditStatus === "2"
          ? "1"
          : "3",
    },
  });
};
// 意见栏发布
const publish = async () => {
  let data = {
    proId: Number(route.query.id),
    viewContent: form.opinion,
  };
  const res = await opinionRelease(data);
  opinionQuery();
  form.opinion = "";
};

const opinionList = ref([]);
// 意见查询
const opinionQuery = async () => {
  let params = {
    viewContent: form.opinion,
    proId: Number(route.query.id),
  };
  const res = await opinionInquiry(params);
  if (res.code === 200 && res.rows) {
    opinionList.value = res.rows;
  }
};
// 保存
//from.addressList
const ruleFormRef = ref();
const storage = async (formEl) => {
  if (!formEl) return;
  await formEl.validate(async (valid, fields) => {
    if (valid) {
      if (datetime.value && datetime.value[0]) {
        contractDuration.value = datetime.value[0];
      }
      if (datetime.value && datetime.value[1]) {
        contractTermination.value = datetime.value[1];
      }
      // 确认立项(分为转立项，新建立项添加)-新建添加
      if (route.query.name === "1" && route.query.showApproval) {
        // 新添加的立项

        let newArray = [];
        let userCcIds;
        let userIds;
        let requestPayload;
        // 编辑默认回显的时候 审批人
        if (check.processCheckBo.checkPeopleIds) {
          userIds = check.processCheckBo.checkPeopleIds.map((item) =>
            item.userId ? Number(item?.userId) : item
          );
        }
        if (check.processCheckBo.copyFor) {
          userCcIds = check.processCheckBo.copyFor.map((item) =>
            item.userId ? Number(item?.userId) : item
          );
        }
        // 如果是逐级审批
        if (check.processCheckBo.checkType === 1) {
          newArray = check.processCheckBo.checkPeopleIds.map((item, index) => {
            return {
              orderNum: index + 1,
              userId: item.userId ? Number(item?.userId) : item,
            };
          });
          requestPayload = {
            ...form,
            contractDuration: contractDuration.value,
            contractTermination: contractTermination.value,
            processCheckBo: {
              orderCheckPeopleInfoList: newArray, // 设置新的 checkPeopleIds 属性值
              copyFor: userCcIds,
              checkType: check.processCheckBo.checkType,
            },
          };
        } else {
          // 自由审批
          if (check.processCheckBo.checkPeopleIds) {
            userIds = check.processCheckBo.checkPeopleIds.map((item) =>
              item.userId ? Number(item?.userId) : item
            );
          }
          requestPayload = {
            ...form,
            contractDuration: contractDuration.value,
            contractTermination: contractTermination.value,
            processCheckBo: {
              checkPeopleIds: userIds, // 设置新的 checkPeopleIds 属性值
              copyFor: userCcIds,
              checkType: check.processCheckBo.checkType,
            },
          };
        }
        
        const res = await approval(requestPayload);
        if (res.code === 200) {
          ElMessage.success("立项成功");
          router.push("/project/lixiang");
        }
      } else if (route.query.name === "1") {
        // 转立项
        if (datetime.value && datetime.value[0]) {
          contractDuration.value = datetime.value[0];
        }
        if (datetime.value && datetime.value[1]) {
          contractTermination.value = datetime.value[1];
        }
        let planId = Number(route.query.planId);
        let newArray = [];
        let userCcIds;
        let userIds;
        let requestPayload;

        if (check.processCheckBo.copyFor) {
          userCcIds = check.processCheckBo.copyFor.map((item) =>
            item.userId ? Number(item?.userId) : item
          );
        }

        // 如果是逐级审批
        if (check.processCheckBo.checkType === 1) {
          newArray = check.processCheckBo.checkPeopleIds.map((item, index) => {
            return {
              orderNum: index + 1,
              userId: item.userId ? Number(item?.userId) : item,
            };
          });
          requestPayload = {
            ...form,
            contractDuration: contractDuration.value,
            contractTermination: contractTermination.value,

            processCheckBo: {
              orderCheckPeopleInfoList: newArray, // 设置新的 checkPeopleIds 属性值
              copyFor: userCcIds,
              checkType: check.processCheckBo.checkType,
            },
          };
        } else {
          // 自由审批
          if (check.processCheckBo.checkPeopleIds) {
            userIds = check.processCheckBo.checkPeopleIds.map((item) =>
              item.userId ? Number(item?.userId) : item
            );
          }
          requestPayload = {
            ...form,
            contractDuration: contractDuration.value,
            contractTermination: contractTermination.value,
            processCheckBo: {
              checkPeopleIds: userIds, // 设置新的 checkPeopleIds 属性值
              copyFor: userCcIds,
              checkType: check.processCheckBo.checkType,
            },
          };
        }

        const res = await approvalAdd(requestPayload, planId);
        if (res.code === 200) {
          ElMessage.success("添加成功");
          router.push("/project/Zhuanhua");
        }
      } else if (route.query.name === "3") {
        // 编辑
        if (datetime.value && datetime.value[0]) {
          contractDuration.value = datetime.value[0];
        }
        if (datetime.value && datetime.value[1]) {
          contractTermination.value = datetime.value[1];
        }
        let params = {
          ...form,
          contractDuration: contractDuration.value,
          contractTermination: contractTermination.value,
        };
        const response = await approvalDetailAdd(params);
        if (response.code === 200) {
          ElMessage.success("保存成功");
          router.push("/project/lixiang");
        }
      } else {
        // 编辑
        if (datetime.value && datetime.value[0]) {
          contractDuration.value = datetime.value[0];
        }
        if (datetime.value && datetime.value[1]) {
          contractTermination.value = datetime.value[1];
        }
        let newArray = [];
        let userCcIds;
        let userIds;
        let requestPayload;
        if (check.processCheckBo.copyFor) {
          userCcIds = check.processCheckBo.copyFor.map((item) =>
            item.userId ? Number(item?.userId) : item
          );
        }

        // 如果是逐级审批
        if (check.processCheckBo.checkType === 1) {
          newArray = check.processCheckBo.checkPeopleIds.map((item, index) => {
            return {
              orderNum: index + 1,
              userId: item.userId ? Number(item?.userId) : item,
            };
          });
          requestPayload = {
            ...form,
            contractDuration: contractDuration.value,
            contractTermination: contractTermination.value,

            processCheckBo: {
              orderCheckPeopleInfoList: newArray, // 设置新的 checkPeopleIds 属性值
              copyFor: userCcIds,
              checkType: check.processCheckBo.checkType,
            },
          };
        } else {
          // 自由审批
          if (check.processCheckBo.checkPeopleIds) {
            userIds = check.processCheckBo.checkPeopleIds.map((item) =>
              item.userId ? Number(item?.userId) : item
            );
          }
          requestPayload = {
            ...form,
            contractDuration: contractDuration.value,
            contractTermination: contractTermination.value,
            processCheckBo: {
              checkPeopleIds: userIds, // 设置新的 checkPeopleIds 属性值
              copyFor: userCcIds,
              checkType: check.processCheckBo.checkType,
            },
          };
        }

        // 保存
        const response = await approvalEdit(requestPayload);
        if (response.code === 200) {
          ElMessage.success("保存成功");
          router.push("/project/lixiang");
        }
      }
    } else {
      console.log("error submit!", fields);
    }
  });
};
// 取消/驳回
const resetForm = async () => {
  if (route.query.name === "6") {
    let data = {
      checkOpinion: form.approvalOpinions,
      id: form.processCheckHistoryId,
      copyFor: check.processCheckBo.copyFor.map((item) => item.userId),
      keepCheckId: check.processCheckBo.checkPeopleIds.map(
        (item) => item.userId
      ),
      state: "0",
      fileList: approvalFile.value,
      keepCheck: keepCheck.value,
    };
    const res = await lxapprovalApi(data);
    if (res.code === 200) {
      ElMessage.success("审批已驳回");
      router.go(-1);
    }
  } else {
    router.go(-1);
  }
};

// 通过
const submitForm = async () => {
  if (route.query.show) {
    // 转立项审批
    let data = {
      checkOpinion: form.approvalOpinions,
      id: form.processCheckHistoryId,
      copyFor: check.processCheckBo.copyFor.map((item) => item.userId),
      keepCheckId: check.processCheckBo.checkPeopleIds.map(
        (item) => item.userId
      ),
      state: "1",
      fileList: approvalFile.value,
      keepCheck: keepCheck.value,
    };
    const res = await approvalTransfer(data);
    if (res.code === 200) {
      ElMessage.success("审批通过");
      router.push({
        path: "/examine",
      });
    }
  } else {
    let data = {
      checkOpinion: form.approvalOpinions,
      id: form.processCheckHistoryId,
      copyFor: check.processCheckBo.copyFor.map((item) => item.userId),
      keepCheckId: check.processCheckBo.checkPeopleIds.map(
        (item) => item.userId
      ),
      state: "1",
      fileList: approvalFile.value,
      keepCheck: keepCheck.value,
    };
    const res = await lxapprovalApi(data);
    if (res.code === 200) {
      ElMessage.success("审批通过");
      router.push({
        path: "/examine",
      });
    }
  }

  // const res = await approvalProcessApi(data);
};

let businessTypeDicData = [];
//获取
const getbusinessTypeDicData = async() => {
  //类型1为'a-j',类型2为'册'
  //返回值示例：
  // [
  //   {
  //       "type": "6,89",
  //       "value": 1
  //   },
  //   {
  //       "type": "[6,88],[6,90]",
  //       "value": 2
  //   }
  // ]
  let response = await getbusinessTypeDic();
  if (response.code === 200 && response.rows.length > 0) {
    businessTypeDicData = response.rows;
  } else {
    console.log(err);
  }

}

onMounted(async () => {
  hasButton();
  form.unites = unitsList[0].label;
  //需要查询：需要文件分类的业务类型的数据
  await getbusinessTypeDicData();
  await businessTypeOptions();
  await getareaList();
  // 转立项
  if (route.query.name === "1" && route.query.planId) {
    (await route.query.id) ? approvalQueryInfo() : projectApproval();
  } else if (route.query.id && route.query.show) {
    // 转立项审批

    (await route.query.id) ? handelApprovalQuery() : projectApproval();
  } else if (route.query.id) {
    // 详情
    (await route.query.id) ? approvalQueryInfo() : projectApproval();
  }

  (await route.query.id) ? opinionQuery() : "";
  // await getDivision();
  await getindustryDown();
  if (route.query.name === "1") {
    form.projectUserDtoList.push(childRef.value.currentPerson);
  }
  if(route.query.creator){
    form.createPerson = route.query.creator;
  }
});
</script>
<style lang="scss" scoped>
.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 10px;
}
.container {
  width: 100%;
  padding: 20px;
  .top-content {
    width: 100%;
    height: 50px;
    border-bottom: 3px solid #409eff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .editTitle {
      font-weight: 600;
    }
    .button_ok {
      margin-right: 20px;
    }
    .button-content {
      position: absolute;
      background: #0092ff;
      transform: rotate(45deg);
      height: 50px;
      width: 50px;
      right: -25px;
      top: -25px;
      text-align: center;
      .button_back {
        transform: rotate(-45deg);
        color: white;
        margin-top: 30px;
      }
    }
  }
  .el-form {
    padding: 20px;
    .title {
      display: flex;
      align-items: center;
      justify-content: space-between;
      h5 {
        font-weight: bold;
      }
    }

    .table-content {
      width: 100%;
      margin-left: 70px;
      max-height: 300px;
      overflow-y: auto;
    }
    .yijian {
      margin-left: 70px;
    }
    .fabu {
      display: flex;
      justify-content: flex-end;
      margin-top: 20px;
    }
    .text-content {
      height: 250px;
      margin-left: 70px;
      background: #f8f8f9;
      margin-top: 20px;
      overflow: auto;
      padding: 20px;
      .custom-concent {
        width: 100%;
        height: 70px;
        display: flex;
        margin-top: 8px;
        .custom-text {
          display: flex;
          width: 100%;
          margin-left: 10px;
          .text-top {
            display: flex;
            flex-direction: column;
            .text-time {
              color: #939393;
              font-size: 16px;
              margin-top: 10px;
            }
          }
          .text-bottom {
            display: flex;
            justify-content: space-between;
          }
        }
        .custom-avatar {
          width: 50px;
          height: 50px;
          border-radius: 10px;
        }
        .custom-reply {
          color: #333;
          font-size: 16px;
          margin-left: 10px;
          word-break: break-all;
        }
      }
    }
  }
}
.form-single-info {
  display: flex;
  justify-content: center;
}
</style>
